package cn.zjj.controller;

import cn.zjj.domain.User;
import cn.zjj.downgrade.FuseDowngradeUtil;
import cn.zjj.feignClient.UserFeignService;
import com.alibaba.csp.sentinel.annotation.SentinelResource;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

@RestController
@RequestMapping("/order")
public class OrderController {
    @Autowired
    private UserFeignService userFeignService;


    @GetMapping("/getById/{id}")
    @SentinelResource(value = "order-getById",fallback = "fallbackmethod",fallbackClass = FuseDowngradeUtil.class)//降级类降级熔断
    public User getById(@PathVariable("id") Long id){
       return  userFeignService.getById(id);
    }

    //本类降级
/*    public User fallbackmethod(@PathVariable("id") Long id,Throwable e){
        e.printStackTrace();
        return  new User(-1L,"熔断","发生熔断了");
    }*/
}
